Skip to main content

Overview

Duet includes an AI assistant that acts as an additional pair programmer in your session. It’s powered by Meta’s Llama 3 8B model running on Cloudflare’s edge network, providing fast responses without leaving your terminal.

Activating the AI

Press Ctrl+G while in a room to open the AI input prompt:
1

Open AI input

Press Ctrl+G in the terminal. You’ll see:
2

Type your question

Ask anything about your code, request help with commands, or get debugging suggestions:
3

Submit with Enter

The AI will respond in the sidebar. Press Esc to cancel without sending.
The AI assistant requires a Cloudflare Worker URL to be configured when starting the Duet server:

AI architecture

The AI runs as a Cloudflare Durable Object, maintaining conversation state per room:
Llama 3 8B Instruct
  • 8 billion parameter model
  • Optimized for instruction following
  • Runs on Cloudflare’s global network
  • Typical response time: 1-3 seconds

AI sidebar

The AI chat appears in a collapsible sidebar on the right side of your terminal:

Keyboard shortcuts

The AI sidebar only appears when your terminal is at least 120 columns wide and 24 rows tall. On smaller windows, the feature is automatically disabled.

Command execution

The AI can execute commands in a Cloudflare Sandbox by wrapping them in <run> tags:

Example conversation

Commands run in an isolated Cloudflare Sandbox, not your shared terminal workspace. The sandbox is ephemeral and destroyed when the room ends.

Conversation persistence

AI messages are synchronized across all participants in real time:
When someone asks the AI a question:
  1. The response is stored in the room’s shared state
  2. An ai_sync event is broadcast to all participants
  3. Everyone’s AI sidebar updates to show the new messages
Late joiners can see the full AI conversation history when they enter the room. The last 50 messages are kept in memory.

Message format

Each message in the conversation includes:
This allows the UI to display who asked each question:

API endpoints

The Cloudflare Worker exposes these AI endpoints:
endpoint
Send a message to the AIRequest body:
Response:
endpoint
Clean up AI state and sandbox for a roomCalled automatically when the last participant leaves.Response:

Client implementation

The Go client communicates with the Worker:
Requests timeout after 30 seconds to prevent hanging if the Worker is slow.

Error handling

If you press Ctrl+G without a Worker URL:
Start the server with the --worker flag.
If the AI doesn’t respond within 30 seconds:
Try again or check your Worker status.
Empty messages are rejected:

Best practices

Be specific

Instead of “help with this code”, ask “how do I parse JSON in Go?”

One question at a time

The AI works best with focused questions. Break complex tasks into steps.

Include context

Mention what you’re trying to do: “I’m debugging a Python script that…”

Review commands

Always verify AI-suggested commands before running them in your terminal.

Limitations

  • The AI doesn’t have access to your terminal history or current directory
  • It can’t see files in your workspace (only in its own sandbox)
  • It doesn’t remember conversations across different rooms
  • The 10-message context window means very long discussions may lose coherence

Next steps

Sandbox execution

Learn how the AI’s command execution sandbox works

Deploy a Worker

Set up your own Cloudflare Worker for AI features